package com.mym;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * @author miao
 * @version 1.0
 * @date 2025/4/18 14:24
 * @description
 */
public class Test1 {
    public static void main(String[] args) {
        // 定义日期字符串
        String dateStr = "2021-08-12";

        // 定义日期格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");

        // 将字符串解析为 LocalDate 对象
        LocalDate date = LocalDate.parse(dateStr, formatter);

        // 获取年、月、日
        int year = date.getYear();
        int month = date.getMonthValue();
        int day = date.getDayOfMonth();

        // 输出结果
        System.out.println("年: " + year);
        System.out.println("月: " + month);
        System.out.println("日: " + day);
    }
}
